<template>
  <div class="api" ref="api">
    <Card shadow class="card">
      <Table
          highlight-row
          stripe
          :loading="loading"
          :max-height="height"
          :columns="columns1"
          :data="data2">
        <template slot-scope="{ row }" slot="operation">
          <Button type="primary" size="small" @click="dtl(row)">详情</Button>
        </template>
      </Table>
      <div class="page">
        <Page :total="page.rowTotal" :page-size="page.pageSize" show-elevator show-total @on-change="toPage"/>
      </div>
    </Card>
    <Modal v-model="modal1" title="详情" width="600">
      <Card :bordered="false" :dis-hover="true">
        <Form>
          <FormItem label="名称">
            {{ modal1Data.url }}
          </FormItem>
          <Row>
            <Col span="12">
              <FormItem label="描述">
               {{ modal1Data.parms }}
              </FormItem>
            </Col>
            <Col span="12">
              <FormItem label="类型">
                {{ modal1Data.type }}
              </FormItem>
            </Col>
          </Row>
          <FormItem label="className">
              {{ modal1Data.className }}
          </FormItem>
        </Form>
      </Card>
    </Modal>
  </div>
</template>

<script>
import {getApiList} from "../../api/data";

export default {
  name: "api",
  data() {
    return {

      columns1: [
        {
          title: '名称',
          key: 'url',
        }, {
          title: '描述',
          key: 'parms',
        }, {
          title: '类型',
          key: 'type',
        }, {
          title: 'className',
          key: 'className',
        }, {
          title: '操作',
          slot: 'operation',
        },
      ],
      loading: true,
      data2: [],
      height: 0,
      page: {
        pageNum: 1,
        pageSize: 10,
        pageTotal: 1,
        rowTotal: 1,
      },
      modal1: false,
      modal1Data: {}
    }
  },
  mounted() {
    this.getApiList();
    this.height = this.$refs.api.offsetHeight - 72
  },
  methods: {
    getApiList() {
      getApiList().then(res => {
        this.loading = false
        console.log(res)
        this.page.rowTotal = res.page.rowTotal
        this.data2 = res.data;
      })
    },
    toPage(pageNum) {
      this.loading = true
      this.page.pageNum = pageNum;
      this.getApiList()
    },
    dtl(e) {
      this.modal1 = true
      this.modal1Data = e
      console.log(e)
    }
  }
}
</script>

<style scoped>
.api {
  height: 100%;
}

.card {
  width: 100%;
  height: 100%;
}

.page {
  margin-top: 10px;
  text-align: right;
}
</style>
